package cn.gson.crm.model.pojos;

import javax.persistence.*;
import java.util.List;
import java.util.Objects;

@Entity
public class Dept {
    private long deptId;
    private String deptName;
    private Long jiId;
    private List<Dept> deptList;
    private Dept dept;
    private List<Functions> functionsList;
    @Column(name="ji_id")
    public Long getJiId() {
        return jiId;
    }

    public void setJiId(Long jiId) {
        this.jiId = jiId;
    }

    @ManyToMany
    @JoinTable(name = "DEPT_FUNCTIONS",
            joinColumns = {
                    @JoinColumn(name="DP_ID")
            },
            inverseJoinColumns = {
                    @JoinColumn(name = "FST_ID")
            })
    public List<Functions> getFunctionsList() {
        return functionsList;
    }

    public void setFunctionsList(List<Functions> functionsList) {
        this.functionsList = functionsList;
    }

    @ManyToOne
    @JoinColumn(name = "DEPT_ID",updatable = false,insertable = false)
    public Dept getDept() {
        return dept;
    }

    public void setDept(Dept dept) {
        this.dept = dept;
    }

    @OneToMany(mappedBy = "dept")
    public List<Dept> getDeptList() {
        return deptList;
    }

    public void setDeptList(List<Dept> deptList) {
        this.deptList = deptList;
    }


    @Id
    @Column(name = "DEPT_ID", nullable = false, precision = 0)
    @GeneratedValue(generator = "seq",strategy = GenerationType.SEQUENCE)
    //定义一个序列生成器
    @SequenceGenerator(name = "seq",sequenceName = "crm",
            initialValue = 1,allocationSize = 1)
    public long getDeptId() {
        return deptId;
    }

    public void setDeptId(long deptId) {
        this.deptId = deptId;
    }

    @Basic
    @Column(name = "DEPT_NAME", nullable = true, length = 255)
    public String getDeptName() {
        return deptName;
    }

    public void setDeptName(String deptName) {
        this.deptName = deptName;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Dept dept = (Dept) o;
        return deptId == dept.deptId &&
                Objects.equals(deptName, dept.deptName);
    }

    @Override
    public int hashCode() {
        return Objects.hash(deptId, deptName);
    }
}
